﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class AllocatedBLL
    {
        static int id=0;
        HospitalDataContext DB = new HospitalDataContext();
        public string Insert(AllocatedDTO all)
        {
            try
            {
                Allocated allocated = new Allocated();
                //allocated.
                allocated.WardID = all.WardId;
                allocated.StaffID = all.StaffId;
                allocated.Shift = all.Shift;
                allocated.DateBegin = all.DateBegin;
                allocated.Status = "Work";
                DB.Allocateds.InsertOnSubmit(allocated);
                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
        public string Update(AllocatedDTO all)
        {
            try
            {
                Allocated allocated = DB.Allocateds.Where(s => s.StaffID == all.StaffId && s.WardID == all.WardId && s.DateBegin == all.DateBegin).FirstOrDefault();
                allocated.Status = "Finish";
                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
    }
}
